home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Mousetools / PWKeys / PWkeys2.0.asm < prev    next >
Assembly Source File  |  1996-09-26  |  42KB  |  1,647 lines

  1. *    PWkeys
  2. *    1991 by Preben Nielsen
  3. *
  4. *
  5. *HISTORY
  6. *          Made with Hisoft V2.12
  7. *
  8. *  V1.0   20-Apr-91: This is first release. I made it over a year ago
  9. *  V1.1   06-May-91: Corrected a bug that appeared when trying to activate
  10. *                    next/previous window when none was active
  11. *         07-May-91: Added 'Refresh Window', 'Minimize Window' and
  12. *                    'Maximize Window'.
  13. *         08-May-91: Added 'Sub Bitplane' and 'Add BitPlane' and
  14. *                    'Toggle Input-Lock'.
  15. *         09-May-91: Added screen-blanking to 'Toggle Input-Lock'.
  16. *         10-May-91: Added mouse-acceleration and sunmouse.
  17. *         14-May-91: Added automatic and persistent screen-blanking.
  18. *         15-May-91: Added automatic and persistent mouse-blanking.
  19. *  V2.0   18-May-91: Now I test for key-releases (saves time).
  20. *         19-May-91: Help, I just found out that my "TellInputDevice"
  21. *                    routine trashes memory-address 0 because it didn't
  22. *                    do a "NewList" on its Message-port. It didn't cause
  23. *                    any problems most of the time, but it has now been
  24. *                    cured.
  25.  
  26.     OPT O+
  27.     OPT O1+            ; Tells when a branch could be optimised to short
  28. ;    OPT i+            ; Tells when '#' is probably missing.
  29.  
  30.         incdir        "AsmInc:"
  31.         include        "exec/exec_lib.i"
  32.         include        "exec/io.i"
  33.         include        "exec/memory.i"
  34.         include        "exec/interrupts.i"
  35.         include        "devices/input.i"
  36.         include        "devices/inputevent.i"
  37.         include        "libraries/dos.i"
  38.         include        "libraries/dosextens.i"
  39.         include        "libraries/dos_lib.i"
  40.         include        "graphics/gfxbase.i"
  41.         include        "graphics/clip.i"
  42.         include        "graphics/layers_lib.i"
  43.         include        "graphics/graphics_lib.i"
  44.         include        "intuition/intuitionbase.i"
  45.         include        "intuition/intuition_lib.i"
  46.         include        "Workbench/startup.i"
  47.         include        "Workbench/workbench.i"
  48.         include        "Workbench/icon_lib.i"
  49.         include        "hardware/custom.i"
  50.         include        "hardware/dmabits.i"
  51.         include        "PWkeys.i"
  52.  
  53. V_EHB        =$80
  54.  
  55. Prepare        MACRO
  56.         IFC        '\1','Exec_Call'
  57.         movea.l        4.W,A6
  58.         ENDC
  59.         IFC        '\1','Icon_Call'
  60.         movea.l        IconBase(DB),A6
  61.         ENDC
  62.         IFC        '\1','Intuition_Call'
  63.         movea.l        IntBase(DB),A6
  64.         ENDC
  65.         IFC        '\1','Gfx_Call'
  66.         movea.l        GFXBase(DB),A6
  67.         ENDC
  68.         IFC        '\1','Dos_Call'
  69.         movea.l        DosBase(DB),A6
  70.         ENDC
  71.         ENDM
  72. CallLib        MACRO
  73.         jsr        _LVO\1(A6)
  74.         ENDM
  75. Call        MACRO
  76.         bsr        \1
  77.         ENDM
  78. CallS        MACRO
  79.         bsr.S        \1
  80.         ENDM
  81. Push        MACRO
  82.         movem.l        \1,-(SP)
  83.         ENDM
  84. Pop        MACRO
  85.         movem.l        (SP)+,\1
  86.         ENDM
  87. PushS        MACRO
  88.         move.l        \1,-(SP)
  89.         ENDM
  90. PopS        MACRO
  91.         move.l        (SP)+,\1
  92.         ENDM
  93. rAPtr        MACRO        name
  94. DefSiz        set        DefSiz+4
  95. DefPtr        set        DefPtr-4
  96. \1        =        DefPtr
  97.         ENDM
  98. rLong        MACRO        name
  99. DefSiz        set        DefSiz+4
  100. DefPtr        set        DefPtr-4
  101. \1        =        DefPtr
  102.         ENDM
  103. rWord        MACRO        name
  104. DefSiz        set        DefSiz+2
  105. DefPtr        set        DefPtr-2
  106. \1        =        DefPtr
  107.         ENDM
  108. rByte        MACRO        name
  109. DefSiz        set        DefSiz+1
  110. DefPtr        set        DefPtr-1
  111. \1        =        DefPtr
  112.         ENDM
  113. rStorage    MACRO        name,size    ; Define storage
  114. DefSiz        set        DefSiz+\2
  115. DefPtr        set        DefPtr-\2
  116. \1        =        DefPtr
  117.         ENDM
  118. rEVEN        MACRO                ; Word boundary
  119.         IFNE        DefPtr&1
  120. DefPtr        set        DefPtr-1
  121. DefSiz        set        DefSiz+1
  122.         ENDC
  123.         ENDM
  124. rStart        MACRO                ; Define var section
  125. DefPtr        set        0
  126. DefSiz        set        0
  127.         ENDM
  128. rEnd        MACRO                ; End var section
  129. RelSize        =        DefSiz
  130.         ENDM
  131. rAlloc        MACRO                ; Allocate vars
  132.         link        DB,#-RelSize
  133.         ENDM
  134. rFree        MACRO                ; Deallocate vars
  135.         unlk        DB
  136.         ENDM
  137. rClear        MACRO                ; Reset all vars
  138.         movem.l        D0/DB,-(SP)
  139.         move.w        #RelSize-1,D0
  140. rClr.\@        clr.b        -(DB)
  141.         dbf        D0,rClr.\@
  142.         movem.l        (SP)+,D0/DB
  143.         ENDM
  144.  
  145. ON_DISPLAY    MACRO
  146.         move.w        #BITSET|DMAF_RASTER,$DFF000+dmacon
  147.         ENDM
  148.  
  149. OFF_DISPLAY    MACRO
  150.         move.w        #BITCLR|DMAF_RASTER,$DFF000+dmacon
  151.         ENDM
  152.  
  153. TEST_DISPLAY    MACRO
  154.         btst        #DMAB_RASTER-8,$DFF000+dmaconr
  155.         ENDM
  156.  
  157. DB        EQUR        A4
  158.  
  159.         SECTION        PWkeys,CODE
  160. InitProcess    rAlloc                    ; Allocate memory for variables
  161.         rClear                    ; Clear the memory
  162.         subq.l        #1,D0
  163.         move.l        A0,CName(DB)
  164.         move.l        D0,CLen(DB)
  165.         Prepare        Exec_Call
  166.         CallLib        Forbid
  167.         lea        IHS+ihs_PortName(PC),A1
  168.         CallLib        FindPort
  169.         move.l        D0,HPort(DB)
  170.         CallLib        Permit
  171.         suba.l        A1,A1
  172.         CallLib        FindTask        ; Find us
  173.         move.l        D0,PProcess(DB)
  174.         movea.l        D0,A2
  175.         tst.l        pr_CLI(A2)
  176.         bne.S        CLIStart
  177. WBStart        lea        pr_MsgPort(A2),A0
  178.         CallLib        WaitPort        ; Wait for a message
  179.         lea        pr_MsgPort(A2),A0
  180.         CallLib        GetMsg            ; then get it
  181.         move.l        D0,WBMsg(DB)        ; save it for later reply
  182.         bra.S        GetLibs
  183. CLIStart    move.l        CName(DB),A0
  184.         move.l        CLen(DB),D0
  185.         clr.b        0(A0,D0.W)
  186. GetLibs        lea        DosName(PC),A1
  187.         CallLib        OldOpenLibrary
  188.         move.l        D0,DosBase(DB)
  189.         beq        Error
  190.  
  191.         tst.l        HPort(DB)        ; Install or Remove ?
  192.         bne.S        LetsBegin
  193.         tst.l        WBMsg(DB)
  194.         beq.S        LetsBegin        ; CLI or WB ?
  195.  
  196.         clr.l        CLen(DB)        ; Signal that we haven't found args yet
  197.         move.l        WBMsg(DB),A2
  198.         move.l        sm_NumArgs(A2),D0    ; Any args ?
  199.         move.l        sm_ArgList(A2),A2
  200.         subq.l        #1,D0
  201.         blt.S        LetsBegin
  202.         beq.S        FoundArg
  203.         addq.w        #wa_SIZEOF,A2        ; PROJECT !
  204. FoundArg    move.l        wa_Lock(A2),D1
  205.         move.l        wa_Name(A2),A2        ; Name of icon
  206.         beq.S        NoLock
  207.         Prepare        Dos_Call
  208.         CallLib        CurrentDir
  209. NoLock        Prepare        Exec_Call
  210.         lea        IconName(PC),A1
  211.         CallLib        OldOpenLibrary
  212.         move.l        D0,IconBase(DB)
  213.         beq.S        LetsBegin
  214.         Prepare        Icon_Call
  215.         move.l        A2,A0
  216.         CallLib        GetDiskObject        ; Get the icon
  217.         move.l        D0,DiskObj(DB)
  218.         beq.S        LetsBegin
  219.         move.l        D0,A2
  220.         move.l        do_ToolTypes(A2),A0
  221.         lea        FileTxt(PC),A1
  222.         CallLib        FindToolType        ; Find 'FILE=????'
  223.         move.l        D0,CName(DB)
  224.         move.l        D0,CLen(DB)        ; Signal that we have or haven't found args
  225. LetsBegin    tst.l        HPort(DB)
  226.         beq.S        DoInstall
  227. DoRemove    moveq        #REMOVED,D7
  228.         lea        IHS(PC),A0
  229.         lea        PSEndIHS1(PC),A1
  230.         lea        PSEndIHS2(PC),A2
  231.         Call        RemoveHandler
  232.         beq.S        ShowMsg
  233.         moveq        #CANTREMOVE,D7
  234.         bra.S        ShowMsg
  235. DoInstall    moveq        #INSTALLED,D7
  236.         lea        IHS(PC),A0
  237.         lea        PSPrepIHS1(PC),A1
  238.         lea        PSPrepIHS2(PC),A2
  239.         Call        InstallHandler
  240.         beq.S        ShowMsg
  241.         moveq        #CANTINSTALL,D7
  242. ShowMsg        move.l        D7,D0
  243.         Call        CONMsg
  244.  
  245. Error
  246. Exit        Prepare        Exec_Call
  247. FreeDos        move.l        DosBase(DB),D0
  248.         beq.S        ReplyWB
  249.         move.l        D0,A1
  250.         CallLib        CloseLibrary
  251. ReplyWB        move.l        WBMsg(DB),D0
  252.         beq.S        AllDone
  253.         move.l        DiskObj(DB),D0
  254.         beq.S        FreeIcon
  255.         move.l        D0,A0
  256.         Prepare        Icon_Call
  257.         CallLib        FreeDiskObject
  258. FreeIcon    Prepare        Exec_Call
  259.         move.l        IconBase(DB),D0
  260.         beq.S        WBEnd
  261.         move.l        D0,A1
  262.         CallLib        CloseLibrary
  263. WBEnd        CallLib        Forbid            ; We were started from WB
  264.         move.l        WBMsg(DB),A1
  265.         CallLib        ReplyMsg        ; Reply WBMessage
  266. AllDone        rFree
  267.         moveq        #0,D0
  268.         rts
  269.  
  270.  
  271. FHandle        EQUR        D5
  272. * Call: D0 = Msg-number
  273. CONMsg        Push        D0-D7/A0-A6
  274.         Prepare        Dos_Call
  275.         move.l        D0,D4
  276.         moveq        #0,D6
  277.         CallLib        Output
  278.         move.l        D0,FHandle
  279.         bne.S        1$
  280.         moveq        #1,D6
  281.         lea        CONName(PC),A0
  282.         move.l        A0,D1
  283.         move.l        #MODE_OLDFILE,D2
  284.         CallLib        Open
  285.         move.l        D0,FHandle
  286.         beq.S        2$
  287. 1$        moveq        #INFOMSG,D0
  288.         Call        SendMsg
  289.         move.l        D4,D0
  290.         Call        SendMsg
  291.         tst.l        D6
  292.         beq.S        2$
  293.         moveq        #127,D1
  294.         CallLib        Delay
  295.         move.l        FHandle,D1
  296.         CallLib        Close
  297. 2$        Pop        D0-D7/A0-A6
  298.         rts
  299.  
  300. * Call: D0 = Msg-number
  301. SendMsg        neg.l        D0
  302.         lsl.l        #1,D0
  303.         lea        MsgTable(PC),A0
  304.         add.w        0(A0,D0),A0
  305.         move.l        A0,D2
  306.         moveq        #-1,D3
  307. 1$        addq.l        #1,D3
  308.         tst.b        (A0)+
  309.         bne.S        1$
  310.         move.l        FHandle,D1
  311.         Prepare        Dos_Call
  312.         CallLib        Write
  313.         rts
  314.  
  315. INFOMSG        =0
  316. INSTALLED    =-1
  317. REMOVED        =-2
  318. CANTINSTALL    =-3
  319. CANTREMOVE    =-4
  320.  
  321. MsgText        MACRO
  322.         dc.w        \1-MsgTable
  323.         ENDM
  324. MsgTable    MsgText        Msg
  325.         MsgText        Msg1
  326.         MsgText        Msg2
  327.         MsgText        Msg3
  328.         MsgText        Msg4
  329.  
  330. CONName        dc.b        'CON:100/60/330/63/PWkeys',0
  331.  
  332. Msg        PWkeys_CON_Msg
  333. Msg1        dc.b        'has just been installed...',10,0
  334. Msg2        dc.b        'has just been removed...',10,0
  335. Msg3        dc.b        'Error: Cannot install handler',10,0
  336. Msg4        dc.b        'Error: Cannot remove handler',10,0
  337.         EVEN
  338.  
  339. rtsValue    EQUR        D7
  340. * This is general-purpose inputhandler removal-routine
  341. * It only needs an ihs with a port-name to remove the handler
  342. * Call:   A0 = ihs
  343. *      A1 = first ihs-installation-routine or NULL
  344. *      A2 = second ihs-installation-routine or NULL
  345. * Return: D0 = 0 means succes
  346. RemoveHandler    Push        D1/rtsValue/A0-A3/A6
  347.         moveq        #-1,rtsValue
  348.         move.l        A2,A3
  349.         move.l        A0,A2
  350.         move.l        A1,D1
  351.         beq.S        1$
  352.         jsr        (A1)        ; A0 = ihs
  353.         beq.S        2$
  354.         move.l        D0,A2
  355. 1$        move.l        A2,A0
  356.         Prepare        Exec_Call
  357.         moveq        #IND_REMHANDLER,D0
  358.         Call        TellInputDevice
  359.         move.l        D0,rtsValue
  360.         bne.S        2$
  361.         lea        ihs_Port(A2),A1
  362.         CallLib        RemPort
  363.         moveq        #0,D0
  364.         bra.S        3$
  365. 2$        moveq        #-1,D0
  366. 3$        move.l        A3,D1
  367.         beq.S        4$
  368.         move.l        A2,A0
  369.         jsr        (A3)        ; A0 = ihs, D0 = 0 means succes
  370. 4$        move.l        rtsValue,D0
  371.         Pop        D1/rtsValue/A0-A3/A6
  372.         rts
  373.  
  374. * This is general-purpose inputhandler installation-routine
  375. * It only needs an ihs with a port-name to install the handler
  376. * Call:   A0 = ihs
  377. *      A1 = first ihs-installation-routine or NULL
  378. *      A2 = second ihs-installation-routine or NULL
  379. * Return: D0 = 0 means succes
  380. InstallHandler    Push        D1/rtsValue/A0-A3/A6
  381.         moveq        #-1,rtsValue
  382.         move.l        A2,A3
  383.         move.l        A0,A2
  384.         move.l        A1,D1
  385.         beq.S        1$
  386.         jsr        (A1)        ; A0 = ihs
  387.         beq.S        2$
  388.         move.l        D0,A2
  389. 1$        move.l        A2,A0
  390.         moveq        #IND_ADDHANDLER,D0
  391.         Call        TellInputDevice
  392.         move.l        D0,rtsValue
  393.         bne.S        2$
  394.         lea        ihs_Port(A2),A1
  395.         lea        ihs_PortName(A2),A0
  396.         move.l        A0,MP+LN_NAME(A1)        ;MsgPort->mp_Node.ln_Name=Name;
  397.         clr.b        MP+LN_PRI(A1)            ;MsgPort->mp_Node.ln_Pri =0;
  398.         move.b        #NT_MSGPORT,MP+LN_TYPE(A1)    ;MsgPort->mp_Node.ln_Type=NT_MSGPORT;
  399.         move.b        #PA_IGNORE,MP_FLAGS(A1)        ;MsgPort->mp_Flags     =PA_IGNORE;
  400.         Prepare        Exec_Call
  401.         CallLib        AddPort
  402.         moveq        #0,D0
  403.         bra.S        3$
  404. 2$        moveq        #-1,D0
  405. 3$        move.l        A3,D1
  406.         beq.S        4$
  407.         move.l        A2,A0
  408.         jsr        (A3)        ; A0 = ihs, D0 = 0 means succes
  409. 4$        move.l        rtsValue,D0
  410.         Pop        D1/rtsValue/A0-A3/A6
  411.         rts
  412.  
  413. * Open the input device. Set up the I/O block to add or remove the
  414. * input handler, and send the request to the input device. Finally,
  415. * close the device
  416. * Call:   A0 = ihs
  417. *      D0 = Function to perform (IND_ADDHANDLER/IND_REMHANDLER)
  418. * Return: D0 = 0 means succes
  419. TellInputDevice    Push        D1-D2/rtsValue/A0-A3/A6
  420.         Prepare        Exec_Call
  421.         moveq        #-1,rtsValue
  422.         move.l        D0,D2
  423.         move.l        A0,A2
  424.         lea        IReq(DB),A0
  425.         moveq        #IOSTD_SIZE,D0
  426.         Call        MemClear
  427.         lea        IPort(DB),A0
  428.         moveq        #MP_SIZE,D0
  429.         Call        MemClear
  430.         move.l        A0,A3
  431.         move.b        #NT_MSGPORT,MP+LN_TYPE(A3)    ; mp_Node.ln_Type=NT_MSGPORT;
  432.         move.b        #PA_SIGNAL,MP_FLAGS(A3)        ; mp_Flags    =PA_SIGNAL;
  433.         moveq        #-1,D0
  434.         CallLib        AllocSignal
  435.         move.b        D0,MP_SIGBIT(A3)        ; mp_SigBit    =MPSigBit;
  436.         bmi.S        2$
  437.         suba.l        A1,A1
  438.         CallLib        FindTask
  439.         move.l        D0,MP_SIGTASK(A3)        ; mp_SigTask     =FindTask(0);
  440.         lea        MP_MSGLIST(A3),A0
  441.         NEWLIST        A0
  442.         lea        IReq(DB),A1
  443.         move.l        A3,IO+MN_REPLYPORT(A1)        ; ExtReq->io_Message.mn_ReplyPort   =taskReplyPort;
  444.         move.b        #NT_MESSAGE,IO+MN+LN_TYPE(A1)    ; ExtReq->io_Message.mn_Node.ln_Type=NT_MESSAGE;
  445.         lea        InputName(PC),A0        ; input.device
  446.         moveq        #0,D0                ; unit#
  447.         moveq        #0,D1                ; flags
  448.         CallLib        OpenDevice
  449.         tst.w        D0                ; flag: error if > 0
  450.         bne.S        1$
  451.         lea        IReq(DB),A1
  452.         move.w        D2,IO_COMMAND(A1)
  453.         lea        ihs_Interrupt(A2),A0
  454.         move.l        A0,IO_DATA(A1)
  455.         CallLib        DoIO
  456.         move.l        D0,rtsValue
  457.         lea        IReq(DB),A1
  458.         CallLib        CloseDevice
  459. 1$        move.b        MP_SIGBIT(A3),D0
  460.         CallLib        FreeSignal
  461. 2$        move.l        rtsValue,D0
  462.         Pop        D1-D2/rtsValue/A0-A3/A6
  463.         rts
  464.  
  465. * Call: A0    = Memory area
  466. *    D0:16 = Count
  467. MemClear    Push        D0-D1/A0
  468.         moveq        #0,D1
  469.         bra.S        2$
  470. 1$        move.b        D1,(A0)+
  471. 2$        dbf        D0,1$
  472.         Pop        D0-D1/A0
  473.         rts
  474.  
  475. * Call: A0   = Source
  476. *    A1   = Destination
  477. *    D0:16= Count
  478. MemCopy        Push        D0/A0-A1
  479.         bra.S        2$
  480. 1$        move.b        (A0)+,(A1)+
  481. 2$        dbf        D0,1$
  482.         Pop        D0/A0-A1
  483.         rts
  484.  
  485. * Each handler should have such a pair of installation-routine
  486. * The first one is passed to InstallHandler in A1 and it
  487. * is called immediately when entering InstallHandler
  488. * The second one is passed to InstallHandler in A2 and it
  489. * is called after attempt to install handler and message-port
  490. * -----------------------------------------------------------------
  491. * Call:   A0 = ihs
  492. * Return: D0 has to point to ihs to be used when installation proceeds
  493. *      If D0 = 0 then installation is aborted
  494. PSPrepIHS1    Push        D1-D2/A0-A3/A6
  495.         moveq        #0,D2
  496.         Call        GetKeys
  497.         beq        2$
  498.         Prepare        Exec_Call
  499.         lea        Entry(PC),A0
  500.         CallLib        AllocEntry
  501.         move.l        D0,MEntry(DB)
  502.         bmi.S        2$            ; Is bit 31 set ?
  503.         move.l        D0,A3
  504.         move.l        ML_ME+0*ME_SIZE(A3),A2
  505.         lea        IHS(PC),A0
  506.         move.l        A2,A1
  507.         move.w        #HandlerSize,D0
  508.         Call        MemCopy            ; Copy handler
  509.         lea        ChipData(PC),A0
  510.         move.l        ML_ME+1*ME_SIZE(A3),A1
  511.         move.w        #ChipSize,D0
  512.         Call        MemCopy            ; Copy CHIP-data
  513.         move.l        A1,NewCopper-IHS(A2)
  514.         lea        MySprite-ChipData(A1),A1
  515.         move.l        A1,NewSprite-IHS(A2)
  516.         move.b        PWkPri(PC),ihs_Interrupt+LN_PRI(A2)    ; HandlerBlock.HInterrupt.is_Node.ln_Pri = PRI;
  517.         lea        HandlerCode-IHS(A2),A0
  518.         move.l        A0,ihs_Interrupt+IS_CODE(A2)        ; HandlerBlock.HInterrupt.is_Code = Handler
  519.         lea        PWkVersionID-IHS(A2),A0
  520.         move.l        A0,ihs_Interrupt+IS_DATA(A2)        ; HandlerBlock.HInterrupt.is_Data = KeyDefines;
  521.         move.w        #HStartFlags,ihs_Flags(A2)
  522.         move.l        A3,ihs_MemEntry(A2)
  523.         lea        LayerName(PC),A1    ; Libraries won't get closed
  524.         CallLib        OldOpenLibrary
  525.         move.l        D0,LAYERbase-IHS(A2)
  526.         beq.S        2$
  527.         lea        GfxName(PC),A1
  528.         CallLib        OldOpenLibrary
  529.         move.l        D0,GFXbase-IHS(A2)
  530.         beq.S        2$
  531.         lea        IntName(PC),A1
  532.         CallLib        OldOpenLibrary
  533.         move.l        D0,INTUIbase-IHS(A2)
  534.         beq.S        2$
  535.         move.l        A2,D2
  536. 2$        move.l        D2,D0
  537.         Pop        D1-D2/A0-A3/A6
  538.         rts
  539. * Call:   A0 = ihs
  540. *         D0 = 0 means everything went perfect
  541. *             -1 means something went wrong during installation
  542. PSPrepIHS2    Push        D0-D1/A0-A1/A6
  543.         tst.l        D0
  544.         beq.S        1$
  545.         move.l        MEntry(DB),D0
  546.         bmi.S        1$        ; Is bit 31 set ?
  547.         move.l        D0,A0
  548.         Prepare        Exec_Call
  549.         CallLib        FreeEntry
  550. 1$        Pop        D0-D1/A0-A1/A6
  551.         rts
  552.  
  553. * Each handler should have such a pair of ending-routine
  554. * The first one is passed to RemoveHandler in A1 and it
  555. * is called immediately when entering RemoveHandler
  556. * The second one is passed to RemoveHandler in A2 and it
  557. * is called after attempt to remove handler and message-port
  558. * -----------------------------------------------------------------
  559. * Call:   A0 = ihs
  560. * Return: D0 has to point to ihs to be used when removal proceeds
  561. *      If D0 = 0 then removal is aborted
  562. PSEndIHS1    Push        D1-D2/A0-A1/A6
  563.         Prepare        Exec_Call
  564.         CallLib        Forbid
  565.         lea        ihs_PortName(A0),A1
  566.         CallLib        FindPort
  567.         move.l        D0,D2
  568.         CallLib        Permit
  569.         move.l        D2,D0            ; Does Forbid/Permit destroy scratch-registers ?
  570.         Pop        D1-D2/A0-A1/A6
  571.         rts
  572. * Call:   A0 = ihs
  573. *         D0 = 0 means everything went perfect
  574. *             -1 means something went wrong during removal
  575. PSEndIHS2    Push        D0-D1/A0-A1/A6
  576.         tst.l        D0
  577.         bmi.S        1$
  578.         move.l        ihs_MemEntry(A0),A0
  579.         Prepare        Exec_Call
  580.         CallLib        FreeEntry
  581. 1$        Pop        D0-D1/A0-A1/A6
  582.         rts
  583.  
  584. * Tries to read hotkeys from file (if any is specified)
  585. * Return: D0 = 0 means failure
  586. GetKeys        Push        D1-D7/A0-A6
  587.         moveq        #1,rtsValue
  588.         tst.l        CLen(DB)
  589.         beq.S        2$
  590.         moveq        #0,rtsValue
  591.         Prepare        Dos_Call
  592.         move.l        CName(DB),D1
  593.         move.l        #MODE_OLDFILE,D2
  594.         CallLib        Open
  595.         move.l        D0,D4
  596.         beq.S        2$
  597.         move.l        D0,D1
  598.         lea        TBuf(DB),A0
  599.         move.l        A0,D2
  600.         move.l        #pw_SIZE,D3
  601.         CallLib        Read
  602.         cmp.l        D0,D3
  603.         bne.S        1$
  604.         lea        TBuf(DB),A0
  605.         movem.l        pw_ID(A0),D0-D1
  606.         movem.l        PWkVersionID(PC),D2-D3
  607.         cmp.l        D0,D2
  608.         bne.S        1$
  609.         cmp.l        D1,D3
  610.         bne.S        1$
  611.         lea        PWkVersionID(PC),A1
  612.         move.l        #pw_SIZE,D0
  613.         Call        MemCopy
  614.         moveq        #1,rtsValue
  615. 1$        move.l        D4,D1
  616.         CallLib        Close
  617. 2$        move.l        rtsValue,D0
  618.         Pop        D1-D7/A0-A6
  619.         rts
  620.  
  621. * »»»»»»»»»»»»»»»»»»»»»» Data-definition start «««««««««««««««««««««««
  622.  rStart
  623.  rLong        CLen
  624.  rAPtr        CName
  625.  rAPtr        PProcess
  626.  rAPtr        WBMsg
  627.  rAPtr        DosBase
  628.  rAPtr        IconBase
  629.  rAPtr        DiskObj
  630.  rAPtr        HPort
  631.  rAPtr        MEntry
  632.  rStorage    IReq,IOSTD_SIZE
  633.  rStorage    IPort,MP_SIZE
  634.  rStorage    TBuf,pw_SIZE
  635.  rEnd
  636.  
  637. DosName        dc.b        'dos.library',0
  638. LayerName    dc.b        'layers.library',0
  639. GfxName        dc.b        'graphics.library',0
  640. IntName        dc.b        'intuition.library',0
  641. IconName    dc.b        'icon.library',0
  642. InputName    dc.b        'input.device',0
  643. FileTxt        dc.b        'FILE',0
  644.         EVEN
  645.  
  646. Entry        ds.b        LN_SIZE
  647.         dc.w        2
  648.         dc.l        MEMF_CLEAR|MEMF_PUBLIC
  649.         dc.l        HandlerSize
  650.         dc.l        MEMF_CLEAR|MEMF_CHIP
  651.         dc.l        ChipSize
  652.  
  653. * »»»»»»»»»»»»»»»»»»»»»» Data-definition end «««««««««««««««««««««««««
  654.  
  655. * »»»»»»»»»»»»»»»»»»»»»» Input-handler start «««««««««««««««««««««««««
  656.  
  657. HDisabled    =0
  658. HNoExtRemoval    =1
  659. HInputDisabled    =2
  660. HAccelMouse    =3
  661. HSunMouse    =4
  662. HScreenBlanked    =5
  663. HMouseBlanked    =6
  664.  
  665. HStartFlags    =0
  666.  
  667. * This is the handler-block
  668. IHS        ihs_Start
  669. * Local variables
  670. Chain        dc.l        0
  671. OldSprite    dc.l        0
  672. NewSprite    dc.l        0
  673. NewCopper    dc.l        0
  674. INTUIbase    dc.l        0
  675. GFXbase        dc.l        0
  676. LAYERbase    dc.l        0
  677.  
  678. * This is the beginning of the part coming from a file
  679. PWkVersionID    dc.l        'PWKF'
  680. PWkVersionNum    dc.w        PWkeysVersion,PWkeysRevision
  681. PWkPri        dc.b        PWkeysPri,0
  682. PWkMouseAccel    dc.b        PWkeysMSpeed
  683. PWkMouseThresh    dc.b        PWkeysMThresh
  684. PWkMTimeout    dc.l        PWkeysMTimeout
  685. PWkSTimeout    dc.l        PWkeysSTimeout
  686. PWkMWaitTime    dc.l        0
  687. PWkSWaitTime    dc.l        0
  688. PWkHotKeys    dc.w        KeyFuncNumber
  689. * These defines are the default when no file is specified
  690. * Keep them sorted on 'Code|Qual'
  691. KeyDefines    HotKey        KP1,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_LEFT_BOTTOM
  692.         HotKey        KP2,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_BOTTOM
  693.         HotKey        KP3,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_RIGHT_BOTTOM
  694.         HotKey        KP4,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_LEFT
  695.         HotKey        KP5,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_CENTER
  696.         HotKey        KP6,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_RIGHT
  697.         HotKey        KP7,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_LEFT_TOP
  698.         HotKey        KP8,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_TOP
  699.         HotKey        KP9,LSHIFT|LAMIGA,LSHIFT|LAMIGA,W_TO_RIGHT_TOP
  700.         HotKey        BACKSPACE,LAMIGA|RAMIGA,LAMIGA|RAMIGA,TOGGLE_INPUTLOCK
  701.         HotKey        TAB,LSHIFT|LAMIGA,LSHIFT|LAMIGA,REFRESH_W
  702.         HotKey        DEL,LAMIGA|RAMIGA,LAMIGA|RAMIGA,TOGGLE_FASTMOUSE
  703.         HotKey        UPARROW,LAMIGA,SHIFT|AMIGA,FRONT_W_TO_BACK
  704.         HotKey        UPARROW,LSHIFT|LAMIGA,SHIFT|AMIGA,W_TO_BACK
  705.         HotKey        UPARROW,RSHIFT|RAMIGA,SHIFT|AMIGA,FRONT_S_TO_BACK
  706.         HotKey        DOWNARROW,LAMIGA,SHIFT|AMIGA,BACK_W_TO_FRONT
  707.         HotKey        DOWNARROW,LSHIFT|LAMIGA,SHIFT|AMIGA,W_TO_FRONT
  708.         HotKey        DOWNARROW,RSHIFT|RAMIGA,SHIFT|AMIGA,BACK_S_TO_FRONT
  709.         HotKey        RIGHTARROW,LSHIFT|LAMIGA,LSHIFT|LAMIGA,ACTIVATE_NEXT_W
  710.         HotKey        LEFTARROW,LSHIFT|LAMIGA,LSHIFT|LAMIGA,ACTIVATE_PREV_W
  711.         HotKey        F1,LSHIFT|LAMIGA,LSHIFT|LAMIGA,MINIMIZE_W
  712.         HotKey        F2,LSHIFT|LAMIGA,LSHIFT|LAMIGA,MAXIMIZE_W
  713.         HotKey        F9,RSHIFT|RAMIGA,RSHIFT|RAMIGA,SUB_BITPLANE
  714.         HotKey        F10,RSHIFT|RAMIGA,RSHIFT|RAMIGA,ADD_BITPLANE
  715.         HotKey        HELP,LAMIGA|RAMIGA,LAMIGA|RAMIGA,TOGGLE_SUNMOUSE
  716.  
  717.  
  718. * This is the end of the part coming from a file
  719. * This table below defines the connection between the
  720. * selected hotkey and the function to perform
  721. JmpEntry_SIZE    =2
  722. JmpEntry    MACRO
  723.         dc.w        \1-JmpTable
  724.         ENDM
  725. JmpTable    JmpEntry    WinToTop
  726.         JmpEntry    WinToBottom
  727.         JmpEntry    WinToLeft
  728.         JmpEntry    WinToRight
  729.         JmpEntry    WinToTL
  730.         JmpEntry    WinToBL
  731.         JmpEntry    WinToTR
  732.         JmpEntry    WinToBR
  733.         JmpEntry    WinToCenter
  734.         JmpEntry    WinToFront
  735.         JmpEntry    WinToBack
  736.         JmpEntry    BackWinToFront
  737.         JmpEntry    FrontWinToBack
  738.         JmpEntry    ActivatePrevWin
  739.         JmpEntry    ActivateNextWin
  740.         JmpEntry    MinimizeWin
  741.         JmpEntry    MaximizeWin
  742.         JmpEntry    RefreshWin
  743.         JmpEntry    BackScrToFront
  744.         JmpEntry    FrontScrToBack
  745.         JmpEntry    SubBitplane
  746.         JmpEntry    AddBitplane
  747.         JmpEntry    ToggleInputLock
  748.         JmpEntry    ToggleFastMouse
  749.         JmpEntry    ToggleSunMouse
  750.  
  751. * Handler()
  752. * This is the input handler.  For each event in the event list:
  753. * If the event is a raw key event, then
  754. *   make the KeyCode longword for that event's code and qualifier,
  755. *   binary search the KeyDefines[] array for a matching entry (only consider
  756. *     the qualifiers specified by the HotKey_Mask).  Since most keys pressed
  757. *     will NOT match a hot-key, we want the search to be as fast as 
  758. *     possible, so we use a binary search rather than a linear search.
  759. * if the key was not a hot key,
  760. *   go on to the next key
  761. * otherwise,
  762. *   perform the function for the specified hot key,
  763. *  remove the hot key from the event list.
  764. * When all the events have been checked, return the event list so that
  765. * Intuition can do its thing.
  766.  
  767. * Subroutines that uses other registers than the ones below, has
  768. * to save them first and restore them afterwards.
  769. SD        EQUR    D0            ; Scratch data register
  770. Accel        EQUR    D1            ; Acceleration
  771. Thresh        EQUR    D2            ; Threshold
  772. Min        EQUR    D1            ; For binary search
  773. Max        EQUR    D2            ; For binary search
  774. Num        EQUR    D3            ; For binary search
  775. TheKey        EQUR    D4            ; For binary search
  776. SA        EQUR    A0            ; Scratch address register
  777. Hkey        EQUR    A1            ; Hotkey
  778. PEvent        EQUR    A2            ; Previous Event
  779. Event        EQUR    A3            ; This Event
  780.  
  781. StatusBits    =IHS+ihs_Flags+1
  782.  
  783. Next        =ie_NextEvent
  784. Class        =ie_Class
  785. Code        =ie_Code
  786. Qual        =ie_Qualifier
  787. Seconds        =ie_TimeStamp+TV_SECS
  788. Micros        =ie_TimeStamp+TV_MICRO
  789.  
  790. ButtonsQual    =IEQUALIFIER_MIDBUTTON|IEQUALIFIER_RBUTTON|IEQUALIFIER_LEFTBUTTON
  791.  
  792. * Call:  A0 = List of InputEvents, A1 = HandlerData
  793. HandlerCode    Push        D1-D4/A0-A3
  794.         lea        Chain(PC),PEvent
  795.         move.l        A0,Next(PEvent)
  796.         btst        #HDisabled,StatusBits(PC)    ; Future feature
  797.         bne        NoMoreEvents
  798. ieLoop        move.l        Next(PEvent),Event
  799.         move.l        Event,SD
  800.         beq        NoMoreEvents
  801.  
  802. * Process TIMER events
  803. CheckTimer    cmpi.b        #IECLASS_TIMER,Class(Event)
  804.         bne.S        CheckMouse
  805.  
  806. CheckSBlanking    btst        #HScreenBlanked,StatusBits(PC)
  807.         bne.S        ForceSBlanking
  808.         move.l        PWkSWaitTime(PC),SD
  809.         beq.S        CheckMBlanking
  810.         cmp.l        Seconds(Event),SD
  811.         bge.S        CheckMBlanking
  812. ForceSBlanking    TEST_DISPLAY            ; Screen should be blanked !
  813.         beq        NeverRemove
  814.         Call        BlankScreen    ; But is isn't, so I blank it !
  815.         bra        NeverRemove
  816. CheckMBlanking    btst        #HMouseBlanked,StatusBits(PC)
  817.         bne.S        ForceMBlanking
  818.         move.l        PWkMWaitTime(PC),SD
  819.         beq        NeverRemove
  820.         cmp.l        Seconds(Event),SD
  821.         bge        NeverRemove
  822. ForceMBlanking    move.l        GFXbase(PC),SA    ; Mouse should be blanked !
  823.         move.l        gb_copinit(SA),SA
  824.         move.w        copinit_sprstrtup+2(SA),SD
  825.         swap        SD
  826.         move.w        copinit_sprstrtup+6(SA),SD
  827.         cmp.l        NewSprite(PC),SD
  828.         beq        NeverRemove
  829.         Call        BlankMouse    ; But it isn't, so I blank it now !
  830.         bra        NeverRemove
  831.  
  832. * Process RAWMOUSE events
  833. CheckMouse    cmpi.b        #IECLASS_RAWMOUSE,Class(Event)
  834.         bne.S        CheckKey
  835.         btst        #HInputDisabled,StatusBits(PC)
  836.         bne        Remove
  837.         Call        BreakSBlanking
  838.         Call        BreakMBlanking
  839.  
  840. CheckFastMouse    btst        #HAccelMouse,StatusBits(PC)
  841.         beq.S        CheckSunMouse
  842.  
  843.         cmpi.w        #IECODE_NOBUTTON,Code(Event)
  844.         bne        NeverRemove
  845.         move.w        Qual(Event),SD
  846.         andi.w        #ButtonsQual,SD
  847.         bne        NeverRemove
  848.  
  849.         moveq        #0,Accel
  850.         moveq        #0,Thresh
  851.         move.b        PWkMouseAccel(PC),Accel
  852.         move.b        PWkMouseThresh(PC),Thresh
  853.         move.w        ie_X(Event),D0
  854.         Call        CalcNewPos
  855.         move.w        D0,ie_X(Event)
  856.         move.w        ie_Y(Event),D0
  857.         Call        CalcNewPos
  858.         move.w        D0,ie_Y(Event)
  859.  
  860. CheckSunMouse    btst        #HSunMouse,StatusBits(PC)
  861.         beq        NeverRemove
  862.         Call        ActivateMWindow
  863.         bra        NeverRemove
  864.  
  865. * Process RAWKey events
  866. CheckKey    cmpi.b        #IECLASS_RAWKEY,Class(Event)
  867.         bne        NeverRemove
  868.         move.w        Code(Event),TheKey    ; Construct a 'Code|Qual' long-word
  869.         btst        #7,TheKey        ; Is it a key-release ?
  870.         bne        DontRemoveKey
  871.         swap        TheKey            ; It is a key-press !
  872.         move.w        Qual(Event),TheKey
  873.         move.w        PWkHotKeys(PC),Max    ; Do Binary-search
  874.         moveq        #-1,Min
  875. SearchLoop    move.w        Max,Num
  876.         add.w        Min,Num
  877.         asr.w        #1,Num
  878.         cmp.w        Num,Min
  879.         beq.S        DontRemoveKey        ; Didn't find a match
  880.         move.w        Num,SD
  881.         lsl.w        #3,SD            ; HotKey_SIZE * Num
  882.         lea        KeyDefines(PC),Hkey
  883.         add.w        SD,Hkey
  884.         move.l        TheKey,SD
  885.         and.l        HotKey_Mask(Hkey),SD    ; TheKey & KeyDefines[Num].HotKey_Mask
  886.         cmp.l        HotKey_ID(Hkey),SD    ; A match ?
  887.         beq.S        Perform
  888.         blt.S        LookLower
  889. LookHigher    move.l        Num,Min            ; (TheKey & KeyDefines[Num].HotKey_Mask) > KeyDefines[Num].HotKey_ID
  890.         bra.S        SearchLoop
  891. LookLower    move.l        Num,Max            ; (TheKey & KeyDefines[Num].HotKey_Mask) < KeyDefines[Num].HotKey_ID
  892.         bra.S        SearchLoop
  893.  
  894. * Found a match
  895. * Hkey = Hotkey
  896. Perform        Push        D0-D7/A0-A6        ; (TheKey & KeyDefines[Num].HotKey_Mask) = KeyDefines[Num].HotKey_ID
  897.         moveq        #0,D0
  898.         move.b        HotKey_Func(Hkey),D0    ; KeyDefines[Num].HotKey_Func
  899.         lsl.w        #1,D0            ; JmpEntry_SIZE * KeyDefines[Num].HotKey_Func
  900.         lea        JmpTable(PC),A2
  901.         add.w        0(A2,D0.W),A2
  902.         btst        #HInputDisabled,StatusBits(PC)
  903.         beq.S        1$
  904.         lea        ToggleInputLock(PC),A0
  905.         cmp.l        A2,A0
  906.         bne.S        2$
  907. 1$        Prepare        Exec_Call
  908.         CallLib        Forbid
  909.         move.l        INTUIbase(PC),A6    ; Intuitionbase stays loaded
  910.         jsr        (A2)            ; Jump to function
  911.         Prepare        Exec_Call
  912.         CallLib        Permit
  913. 2$        Pop        D0-D7/A0-A6
  914. RemoveKey    btst        #HInputDisabled,StatusBits(PC)
  915.         bne.S        Remove
  916.         Call        BreakSBlanking
  917. Remove        move.l        Next(Event),Next(PEvent); Remove event from chain and move on to next Event
  918.         bra        ieLoop
  919. DontRemoveKey    btst        #HInputDisabled,StatusBits(PC)
  920.         bne.S        Remove
  921.         Call        BreakSBlanking
  922. NeverRemove    move.l        Event,PEvent        ; Just move on to next Event
  923.         bra        ieLoop
  924. NoMoreEvents    Pop        D1-D4/A0-A3
  925.         move.l        Chain(PC),D0        ; Return (shortened ?) chain
  926.         rts
  927.  
  928. * »»»»»»»»»»» Misc functions called by the hotkey-functions ««««««««««
  929.  
  930. * Call:   A0 = Window to check
  931. * Return: Z-flag set if no active stringgadget or system-gadget
  932. *      in the window or in any active requester in the window
  933. * Destroys no registers
  934. CheckWindow    Push        D0/A1
  935.         move.l        wd_FirstRequest(A0),D0
  936.         beq.S        TestWin
  937. ReqCLoop    tst.l        D0
  938.         beq.S        WinCEnd
  939.         move.l        D0,A1
  940.         move.w        rq_Flags(A1),D0
  941.         andi.w        #REQACTIVE,D0
  942.         beq.S        NextReq
  943.         move.l        rq_ReqGadget(A1),D0
  944.         bra.S        GadCLoop    ; Found an active requester
  945. NextReq        move.l        rq_OlderRequest(A1),D0
  946.         bra.S        ReqCLoop
  947. TestWin        move.l        wd_FirstGadget(A0),D0
  948. * D0 = Gadgetlist to check
  949. GadCLoop    tst.l        D0
  950.         beq.S        WinCEnd
  951.         move.l        D0,A1
  952.         move.w        gg_GadgetType(A1),D0
  953.         andi.w        #SYSGADGET,D0
  954.         bne.S        CheckSELECT
  955.         move.w        gg_GadgetType(A1),D0
  956.         andi.w        #STRGADGET,D0
  957.         beq.S        NextGad
  958. CheckSELECT    move.w        gg_Flags(A1),D0
  959.         andi.w        #SELECTED,D0
  960.         beq.S        NextGad
  961.         moveq        #1,D0        ; Window contains an active string-gadget
  962.         bra.S        WinCEnd        ; or an active system-gadget
  963. NextGad        move.l        gg_NextGadget(A1),D0
  964.         bra.S        GadCLoop
  965. WinCEnd        Pop        D0/A1
  966.         rts
  967.  
  968. * TopScreen()
  969. * Find the top screen
  970. * Return: D0 = Screen or NULL
  971. * Destroys D0-D1/A0-A1
  972. TopScreen    move.l        ib_FirstScreen(A6),D0
  973.         rts
  974.  
  975. * BottomScreen()
  976. * Find the bottom screen
  977. * Return: D0 = Screen or NULL
  978. * Destroys D0-D1/A0-A1
  979. BottomScreen    move.l        ib_FirstScreen(A6),D0
  980.         beq.S        2$
  981. 1$        move.l        D0,A0
  982.         move.l        sc_NextScreen(A0),D0
  983.         bne.S        1$
  984.         move.l        A0,D0
  985. 2$        rts
  986.  
  987. * TopWindow()
  988. * Find the top window of the specified screen. Start at the top
  989. * layer of the screen and move backward as long as the layer exists
  990. * and has no window connected to it. Return the window associated
  991. * with the final layer, if any.
  992. * Call  : A0 = Screen
  993. * Return: D0 = Window or NULL
  994. * Destroys D0-D1/A0-A1
  995. TopWindow    move.l        sc_LayerInfo+li_top_layer(A0),A0
  996.         moveq        #0,D0
  997. 1$        move.l        A0,D1
  998.         beq.S        2$
  999.         move.l        lr_Window(A0),D0
  1000.         bne.S        2$
  1001.         move.l        lr_back(A0),A0
  1002.         bra.S        1$
  1003. 2$        tst.l        D0
  1004.         rts
  1005.  
  1006. * BottomWindow()
  1007. * Find the bottom window of the specified screen. Start at the top 
  1008. * layer and as long as the layer exists, go to the next layer back.
  1009. * If the layer has a window attached, consider that to be the bottom
  1010. * window until a lower one is found.
  1011. * Call  : A0 = Screen
  1012. * Return: D0 = Window or NULL
  1013. * Destroys D0-D1/A0-A1
  1014. BottomWindow    move.l        sc_LayerInfo+li_top_layer(A0),A0
  1015.         moveq        #0,D0
  1016. 1$        move.l        A0,D1
  1017.         beq.S        3$
  1018.         move.l        lr_Window(A0),D1
  1019.         beq.S        2$
  1020.         move.l        D1,D0
  1021. 2$        move.l        lr_back(A0),A0
  1022.         bra.S        1$
  1023. 3$        tst.l        D0
  1024.         rts
  1025.  
  1026. * NextWindow()
  1027. * Find the next window below the specified window (wrap arround to
  1028. * the top if the window is the bottom one). Start with the window's
  1029. * layer and go back until a layer with a window is found, or no more
  1030. * layers exist. If a window was found, return it, otherwise, use the
  1031. * top window.
  1032. * Call  : A0 = Window
  1033. * Return: D0 = Next Window or NULL
  1034. * Destroys D0-D1/A0-A1
  1035. NextWindow    moveq        #0,D0
  1036.         move.l        wd_WLayer(A0),A1
  1037. 1$        move.l        lr_back(A1),D1
  1038.         beq.S        2$
  1039.         move.l        D1,A1
  1040.         move.l        lr_Window(A1),D0
  1041.         beq.S        1$
  1042.         cmp.l        A0,D0
  1043.         beq.S        1$
  1044. 2$        tst.l        D0
  1045.         rts
  1046.  
  1047. * PreviousWindow()
  1048. * Find the window that is on top of the specified window (or NULL if there
  1049. * are no windows above it). Start with the window's layer, and move to
  1050. * the layer in front until a layer with a (different) window is found, or
  1051. * until no more layers exist. If a window was found, return it, otherwise
  1052. * return NULL.
  1053. * Call  : A0 = Window
  1054. * Return: D0 = Previous Window or NULL
  1055. * Destroys D0-D1/A0-A1
  1056. PrevWindow    moveq        #0,D0
  1057.         move.l        wd_WLayer(A0),A1
  1058. 1$        move.l        lr_front(A1),D1
  1059.         beq.S        2$
  1060.         move.l        D1,A1
  1061.         move.l        lr_Window(A1),D0
  1062.         beq.S        1$
  1063.         cmp.l        A0,D0
  1064.         beq.S        1$
  1065. 2$        tst.l        D0
  1066.         rts
  1067.  
  1068. ScreenToBack    jmp        _LVOScreenToBack(A6)
  1069. ScreenToFront    jmp        _LVOScreenToFront(A6)
  1070. WindowToBack    Call        CheckWindow
  1071.         bne.S        WinErr
  1072.         jmp        _LVOWindowToBack(A6)
  1073. WindowToFront    Call        CheckWindow
  1074.         bne.S        WinErr
  1075.         jmp        _LVOWindowToFront(A6)
  1076. ActivateWindow    Call        CheckWindow
  1077.         bne.S        WinErr
  1078.         jmp        _LVOActivateWindow(A6)
  1079. MoveWindow    Call        CheckWindow
  1080.         bne.S        WinErr
  1081.         jmp        _LVOMoveWindow(A6)
  1082. SizeWindow    Call        CheckWindow
  1083.         bne.S        WinErr
  1084.         jmp        _LVOSizeWindow(A6)
  1085. WinErr        rts
  1086.  
  1087.  
  1088. * »»»»»»»»»»»»»»»»»»» Window manipulating functions ««««««««««««««««««
  1089.  
  1090. * Move the active window in x/y directions
  1091. * Destroys D0-D1/A0-A2
  1092. WinToTop    lea        TopIt(PC),A1        ; Window To Top
  1093.         lea        DontMoveX(PC),A2
  1094.         bra.S        WindowMove
  1095. WinToBottom    lea        BottomIt(PC),A1        ; Window To Bottom
  1096.         lea        DontMoveX(PC),A2
  1097.         bra.S        WindowMove
  1098. WinToLeft    lea        DontMoveY(PC),A1    ; Window To Left
  1099.         lea        LeftIt(PC),A2
  1100.         bra.S        WindowMove
  1101. WinToRight    lea        DontMoveY(PC),A1    ; Window To Right
  1102.         lea        RightIt(PC),A2
  1103.         bra.S        WindowMove
  1104. WinToTL        lea        TopIt(PC),A1        ; Window To Upper Left Corner
  1105.         lea        LeftIt(PC),A2
  1106.         bra.S        WindowMove
  1107. WinToTR        lea        TopIt(PC),A1        ; Window To Upper Right Corner
  1108.         lea        RightIt(PC),A2
  1109.         bra.S        WindowMove
  1110. WinToBL        lea        BottomIt(PC),A1        ; Window To Lower Left Corner
  1111.         lea        LeftIt(PC),A2
  1112.         bra.S        WindowMove
  1113. WinToBR        lea        BottomIt(PC),A1        ; Window To Lower Right Corner
  1114.         lea        RightIt(PC),A2
  1115.         bra.S        WindowMove
  1116. WinToCenter    lea        CenterHeight(PC),A1    ; Window To Center
  1117.         lea        CenterWidth(PC),A2
  1118. * Call:    A1 = Function to adjust position in y-direction
  1119. *    A2 = Function to adjust position in x-direction
  1120. WindowMove    move.l        ib_ActiveWindow(A6),D0
  1121.         beq.S        2$
  1122.         move.l        D0,A0
  1123.         jsr        (A1)
  1124.         move.w        D0,D1
  1125.         jsr        (A2)
  1126.         bne.S        1$
  1127.         tst.w        D1
  1128.         beq.S        2$
  1129. 1$        Call        MoveWindow
  1130. 2$        rts
  1131.  
  1132. DontMoveX
  1133. DontMoveY    moveq        #0,D0
  1134.         rts
  1135. * Call:    A0 = Window
  1136. CenterHeight    move.l        wd_WScreen(A0),A1
  1137.         move.w        sc_Height(A1),D0
  1138.         sub.w        wd_Height(A0),D0
  1139.         asr.w        #1,D0
  1140.         sub.w        wd_TopEdge(A0),D0
  1141.         rts
  1142. * Call:    A0 = Window
  1143. CenterWidth    move.l        wd_WScreen(A0),A1
  1144.         move.w        sc_Width(A1),D0
  1145.         sub.w        wd_Width(A0),D0
  1146.         asr.w        #1,D0
  1147.         sub.w        wd_LeftEdge(A0),D0
  1148.         rts
  1149. * Call:    A0 = Window
  1150. BottomIt    move.l        wd_WScreen(A0),A1
  1151.         move.w        sc_Height(A1),D0
  1152.         sub.w        wd_TopEdge(A0),D0
  1153.         sub.w        wd_Height(A0),D0
  1154.         rts
  1155. * Call:    A0 = Window
  1156. RightIt        move.l        wd_WScreen(A0),A1
  1157.         move.w        sc_Width(A1),D0
  1158.         sub.w        wd_LeftEdge(A0),D0
  1159.         sub.w        wd_Width(A0),D0
  1160.         rts
  1161. * Call:    A0 = Window
  1162. TopIt        move.w        wd_TopEdge(A0),D0
  1163.         neg.w        D0
  1164.         rts
  1165. * Call:    A0 = Window
  1166. LeftIt        move.w        wd_LeftEdge(A0),D0
  1167.         neg.w        D0
  1168.         rts
  1169.  
  1170. * WinToFront()
  1171. * Send the active window to the top of the list.
  1172. * Destroys D0-D2/A0-A1
  1173. WinToFront    move.l        ib_ActiveScreen(A6),D0
  1174.         beq.S        1$
  1175.         move.l        ib_ActiveWindow(A6),D2
  1176.         beq.S        1$
  1177.         move.l        D0,A0
  1178.         Call        TopWindow
  1179.         cmp.l        D0,D2        ; Same window ? (NOT NULL !)
  1180.         beq.S        1$
  1181.         move.l        D2,A0
  1182.         Call        WindowToFront
  1183. 1$        rts
  1184.  
  1185. * WinToBack()
  1186. * Send the active window to the back of the list.
  1187. * Destroys D0-D2/A0-A1
  1188. WinToBack    move.l        ib_ActiveScreen(A6),D0
  1189.         beq.S        1$
  1190.         move.l        ib_ActiveWindow(A6),D2
  1191.         beq.S        1$
  1192.         move.l        D0,A0
  1193.         Call        BottomWindow
  1194.         cmp.l        D0,D2        ; Same window ? (NOT NULL !)
  1195.         beq.S        1$
  1196.         move.l        D2,A0
  1197.          Call        WindowToBack
  1198. 1$        rts
  1199.  
  1200. * BackWindowToFront()
  1201. * Move the bottom window to the top and activate it.
  1202. * Get the bottom window, skipping over backdrop windows. If one
  1203. * is found, bring it to the front, and activate it.
  1204. * Destroys D0-D2/A0-A1
  1205. BackWinToFront    move.l        ib_ActiveScreen(A6),D0
  1206.         beq.S        3$
  1207.         move.l        D0,A0
  1208.         Call        BottomWindow
  1209. 1$        move.l        D0,A0
  1210.         tst.l        D0
  1211.         beq.S        3$
  1212.         btst        #0,wd_Flags+2(A0)    ; BackDrop ?
  1213.         beq.S        2$
  1214.         Call        PrevWindow
  1215.         bra.S        1$
  1216. 2$        move.l        A0,D2
  1217.         Call        WindowToFront
  1218.         move.l        D2,A0
  1219.         Call        ActivateWindow
  1220. 3$        rts
  1221.  
  1222. * FrontWindowToBack()
  1223. * Move the top window to the back, and activate the new top window.
  1224. * Get the top window, send it top to the back, and activate the top
  1225. * window.
  1226. * Destroys D0-D2/A0-A1
  1227. FrontWinToBack    move.l        ib_ActiveScreen(A6),D2
  1228.         beq.S        1$
  1229.         move.l        D2,A0
  1230.         Call        TopWindow
  1231.         beq.S        1$
  1232.         move.l        D0,A0
  1233.         Call        WindowToBack
  1234.         move.l        D2,A0
  1235.         Call        TopWindow
  1236.         beq.S        1$
  1237.         move.l        D0,A0
  1238.         Call        ActivateWindow
  1239. 1$        rts
  1240.  
  1241. * ActivatePreviousWindow()
  1242. * Get the window previous to the active window (if none, then get the
  1243. * bottom window in the active screen), and activate that window.
  1244. * Destroys D0-D2/A0-A1
  1245. ActivatePrevWin    move.l        ib_ActiveScreen(A6),D2
  1246.         beq.S        3$
  1247.         move.l        ib_ActiveWindow(A6),D0
  1248.         beq.S        1$
  1249.         move.l        D0,A0
  1250.         Call        PrevWindow
  1251.         bne.S        2$
  1252.         move.l        D2,A0
  1253.         Call        BottomWindow
  1254.         bra.S        2$
  1255. 1$        move.l        D2,A0
  1256.         move.l        sc_FirstWindow(A0),D0
  1257. 2$        beq.S        3$
  1258.         move.l        D0,A0
  1259.         Call        ActivateWindow
  1260. 3$        rts
  1261.  
  1262. * ActivateNextWindow()
  1263. * Get the window below the active window and activate it.
  1264. * Destroys D0-D2/A0-A1
  1265. ActivateNextWin    move.l        ib_ActiveScreen(A6),D2
  1266.         beq.S        3$
  1267.         move.l        ib_ActiveWindow(A6),D0
  1268.         beq.S        1$
  1269.         move.l        D0,A0
  1270.         Call        NextWindow
  1271.         bne.S        2$
  1272.         move.l        D2,A0
  1273.         Call        TopWindow
  1274.         bra.S        2$
  1275. 1$        move.l        D2,A0
  1276.         move.l        sc_FirstWindow(A0),D0
  1277. 2$        beq.S        3$
  1278.         move.l        D0,A0
  1279.         Call        ActivateWindow
  1280. 3$        rts
  1281.  
  1282. * Size the active window in x/y directions
  1283. * Destroys D0-D1/A0-A2
  1284. MinimizeWin    lea        MinimizeY(PC),A1
  1285.         lea        MinimizeX(PC),A2
  1286.         bra.S        WindowSize
  1287. MaximizeWin    lea        MaximizeY(PC),A1
  1288.         lea        MaximizeX(PC),A2
  1289. * Call:    A1 = Function to adjust size in y-direction
  1290. *     A2 = Function to adjust size in x-direction
  1291. WindowSize    move.l        ib_ActiveWindow(A6),D0
  1292.         beq.S        2$
  1293.         move.l        D0,A0
  1294.         move.l        wd_Flags(A0),D0
  1295.         andi.w        #WINDOWSIZING,D0
  1296.         beq.S        2$
  1297.         jsr        (A1)
  1298.         move.w        D0,D1
  1299.         jsr        (A2)
  1300.         bne.S        1$
  1301.         tst.w        D1
  1302.         beq.S        2$
  1303. 1$        Call        SizeWindow
  1304. 2$        rts
  1305.  
  1306. * Call:    A0 = Window
  1307. MinimizeY    move.w        wd_MinHeight(A0),D0
  1308.         sub.w        wd_Height(A0),D0
  1309.         rts
  1310. * Call:    A0 = Window
  1311. MinimizeX    move.w        wd_MinWidth(A0),D0
  1312.         sub.w        wd_Width(A0),D0
  1313.         rts
  1314. * Call:    A0 = Window
  1315. MaximizeY    move.l        wd_WScreen(A0),A1
  1316.         move.w        sc_Height(A1),D0
  1317.         sub.w        wd_TopEdge(A0),D0
  1318.         cmp.w        #$FFFF,wd_MaxHeight(A0)
  1319.         beq.S        1$
  1320.         cmp.w        wd_MaxHeight(A0),D0
  1321.         ble.S        1$
  1322.         move.w        wd_MaxHeight(A0),D0
  1323. 1$        sub.w        wd_Height(A0),D0
  1324.         rts
  1325. * Call:    A0 = Window
  1326. MaximizeX    move.l        wd_WScreen(A0),A1
  1327.         move.w        sc_Width(A1),D0
  1328.         sub.w        wd_LeftEdge(A0),D0
  1329.         cmp.w        #$FFFF,wd_MaxWidth(A0)
  1330.         beq.S        1$
  1331.         cmp.w        wd_MaxWidth(A0),D0
  1332.         ble.S        1$
  1333.         move.w        wd_MaxWidth(A0),D0
  1334. 1$        sub.w        wd_Width(A0),D0
  1335.         rts
  1336.  
  1337.  
  1338. * Refresh the active windows border and gadgets
  1339. * Destroys D0-D1/A0-A1
  1340. RefreshWin    move.l        ib_ActiveWindow(A6),D0
  1341.         beq.S        1$
  1342.         move.l        D0,A0
  1343.         CallLib        RefreshWindowFrame
  1344. 1$        rts
  1345.  
  1346.  
  1347. * »»»»»»»»»»»»»»»»»»» Screen manipulating functions ««««««««««««««««««
  1348.  
  1349. * BackScrToFront()
  1350. * Bring the bottom-most screen to the top, and activate its top window.
  1351. * While there is a screen following the active one, move the the next screen.
  1352. * Bring that screen to the front and find its top window.  If one was found,
  1353. * activate the window.
  1354. * Destroys D0-D1/A0-A1
  1355. BackScrToFront    Call        BottomScreen
  1356.         beq.S        1$
  1357.         move.l        D0,A0
  1358.         PushS        A0
  1359.         Call        ScreenToFront
  1360.         PopS        A0
  1361.         Call        TopWindow
  1362.         beq.S        1$
  1363.         move.l        D0,A0
  1364.         Call        ActivateWindow
  1365. 1$        rts
  1366.  
  1367. * FrontScreenToBack()
  1368. * Move the top screen to the back and activate the top window on the new
  1369. * top screen.
  1370. * Destroys D0-D1/A0-A1
  1371. FrontScrToBack    Call        TopScreen
  1372.         beq.S        1$
  1373.         move.l        D0,A0
  1374.         PushS        A0
  1375.         Call        ScreenToBack
  1376.         PopS        A0
  1377.         Call        TopWindow
  1378.         beq.S        1$
  1379.         move.l        D0,A0
  1380.         Call        ActivateWindow
  1381. 1$        rts
  1382.  
  1383. Planes        EQUR        D2
  1384. Index        EQUR        D3
  1385. WScreen        EQUR        A2
  1386. WBitMap        EQUR        A3
  1387. WViewPort    EQUR        A4
  1388. LORESMAX    =6
  1389. HIRESMAX    =4
  1390.  
  1391. * Subtracts a bitplane from the active screen.
  1392. * HAM-screens won't be touched.
  1393. * EHB-screens won't be EHB-screens after this.
  1394. * Destroys D0-D3/A0-A4
  1395. SubBitplane    Call        ASCommon
  1396.         beq.S        2$
  1397.         move.w        vp_Modes(WViewPort),D0
  1398.         andi.w        #V_HAM,D0
  1399.         bne.S        2$            ; Don't touch HAM
  1400.         subq.w        #1,Planes
  1401.         beq.S        2$
  1402.         move.b        Planes,bm_Depth(WBitMap)
  1403.         move.w        Planes,Index
  1404.         mulu        #4,Index
  1405.         move.l        bm_Planes(WBitMap,Index),A0
  1406.         clr.l        bm_Planes(WBitMap,Index)
  1407.         move.w        sc_Width(WScreen),D0
  1408.         move.w        sc_Height(WScreen),D1
  1409.         move.l        GFXbase(PC),A6
  1410.         CallLib        FreeRaster
  1411.         cmp.b        #LORESMAX,Planes
  1412.         bge.S        1$
  1413.         andi.w        #~V_EHB,vp_Modes(a1)    ; Clear EHB flag
  1414. 1$        move.l        INTUIbase(PC),A6
  1415.         CallLib        RemakeDisplay
  1416. 2$        rts
  1417.  
  1418. * Adds a bitplane to the active screen (if enough CHIP-memory).
  1419. * HIRES-screens can get a maximum of 4 bitplanes.
  1420. * LORES-screens can get a maximum of 6 bitplanes (6 bitplanes means EHB).
  1421. * Destroys D0-D3/A0-A4
  1422. AddBitplane    Call        ASCommon
  1423.         beq.S        3$
  1424.         move.w        Planes,Index
  1425.         mulu        #4,Index
  1426.         addq.w        #1,Planes
  1427.         moveq        #HIRESMAX,D1
  1428.         move.w        vp_Modes(WViewPort),D0
  1429.         andi.w        #V_HIRES,D0        ; HIRES ?
  1430.         bne.S        1$
  1431.         moveq        #LORESMAX,D1
  1432. 1$        cmp.w        D1,Planes
  1433.         bgt.S        3$
  1434.         move.w        sc_Width(WScreen),D0
  1435.         move.w        sc_Height(WScreen),D1
  1436.         move.l        GFXbase(PC),A6
  1437.         CallLib        AllocRaster
  1438.         move.l        D0,bm_Planes(WBitMap,Index)
  1439.         beq.S        3$
  1440.         move.l        D0,A1
  1441.         move.w        bm_Rows(WBitMap),D0
  1442.         swap        D0
  1443.         move.w        bm_BytesPerRow(WBitMap),D0
  1444.         moveq        #2,D1
  1445.         CallLib        BltClear
  1446.         move.b        Planes,bm_Depth(WBitMap)
  1447.         cmp.w        #LORESMAX,Planes
  1448.         blt.S        2$
  1449.         ori.w        #V_EHB,vp_Modes(WViewPort)    ; Depth >= 6 => set EHB flag !
  1450. 2$        move.l        INTUIbase(PC),A6
  1451.         CallLib        RemakeDisplay
  1452. 3$        rts
  1453.  
  1454. ASCommon    move.l        ib_ActiveScreen(A6),D0
  1455.         beq.S        1$
  1456.         move.l        D0,WScreen
  1457.         lea        sc_BitMap(WScreen),WBitMap
  1458.         lea        sc_ViewPort(WScreen),WViewPort
  1459.         moveq        #0,Planes
  1460.         move.b        bm_Depth(WBitMap),Planes
  1461. 1$        rts
  1462.  
  1463. * »»»»»»»»»»»»»»»»»»» Misc manipulating functions ««««««««««««««««««««
  1464.  
  1465. * Enables/Disables RAWKEY/RAWMOUSE events
  1466. * Destroys D0-D1/A0-A1
  1467. ToggleInputLock    lea        StatusBits(PC),A0
  1468.         bchg        #HInputDisabled,(A0)
  1469.         beq.S        BlankScreen
  1470.         bra.S        BreakSBlanking
  1471.  
  1472. * Enables/Disables mouse-acceleration
  1473. * Destroys D0-D1/A0-A1
  1474. ToggleFastMouse    lea        StatusBits(PC),A0
  1475.         bchg        #HAccelMouse,(A0)
  1476.         rts
  1477.  
  1478. * Enables/Disables sun-mouse
  1479. * Destroys D0-D1/A0-A1
  1480. ToggleSunMouse    lea        StatusBits(PC),A0
  1481.         bchg        #HSunMouse,(A0)
  1482.         rts
  1483.  
  1484. * »»»»»»»»»»»»»»» Misc functions called by handler «««««««««««««««««««
  1485.  
  1486. * Blanks the screen by installing a temporary copper-list, which
  1487. * ensures a black display, and then turning the raster-DMA off.
  1488. BlankScreen    Push        D1-D7/A0-A2/A6
  1489.         Prepare        Exec_Call
  1490.         CallLib        Forbid
  1491.         lea        StatusBits(PC),A0
  1492.         bset        #HScreenBlanked,(A0)
  1493.         move.l        GFXbase(PC),A6
  1494.         move.l        gb_ActiView(A6),A1
  1495.         move.l        v_LOFCprList(A1),A2
  1496.         movem.w        (A2),D2-D7    ; Save CprList (10 bytes)
  1497.         clr.l        crl_Next(A2)
  1498.         move.l        NewCopper(PC),crl_start(A2)
  1499.         CallLib        LoadView    ; Install a one-color copperlist
  1500.         OFF_DISPLAY
  1501.         movem.w        D2-D7,(A2)     ; Restore CprList (10 bytes)
  1502.         Prepare        Exec_Call
  1503.         CallLib        Permit
  1504.         Pop        D1-D7/A0-A2/A6
  1505.         rts
  1506.  
  1507. * Sets new screen-blanking timeout and turns the raster-DMA 
  1508. * back on, if it is off.
  1509. BreakSBlanking    move.l        PWkSTimeout(PC),D0
  1510.         beq.S        1$
  1511.         add.l        Seconds(Event),D0
  1512. 1$        lea        PWkSWaitTime(PC),A0
  1513.         move.l        D0,(A0)
  1514.         lea        StatusBits(PC),A0
  1515.         bclr        #HScreenBlanked,(A0)
  1516.         beq.S        2$
  1517.         PushS        A6
  1518.         move.l        GFXbase(PC),A6
  1519.         move.l        gb_ActiView(A6),A1
  1520.         CallLib        LoadView
  1521.         ON_DISPLAY
  1522.         PopS        A6
  1523. 2$        rts
  1524.  
  1525. * Blanks the mouse by installing an invisible image for sprite 0
  1526. * in the copper-list
  1527. BlankMouse    PushS        A6
  1528.         Prepare        Exec_Call
  1529.         CallLib        Forbid
  1530.         move.l        GFXbase(PC),A1
  1531.         move.l        gb_copinit(A1),A1
  1532.         lea        copinit_sprstrtup(A1),A1
  1533.         cmp.w        #$0120,(A1)
  1534.         bne.S        2$
  1535.         cmp.w        #$0122,4(A1)
  1536.         bne.S        2$
  1537.         lea        StatusBits(PC),A0
  1538.         bset        #HMouseBlanked,(A0)
  1539.         bne.S        1$
  1540.         lea        OldSprite(PC),A0
  1541.         move.w        2(A1),(A0)+
  1542.         move.w        6(A1),(A0)
  1543. 1$        lea        NewSprite(PC),A0
  1544.         move.w        (A0)+,2(A1)
  1545.         move.w        (A0),6(A1)
  1546. 2$        Prepare        Exec_Call
  1547.         CallLib        Permit
  1548.         PopS        A6
  1549.         rts
  1550.  
  1551. * Sets new mouse-blanking timeout and restores the old
  1552. * sprite 0 image, if the mouse is off.
  1553. BreakMBlanking    PushS        A6
  1554.         move.l        PWkMTimeout(PC),D0
  1555.         beq.S        1$
  1556.         add.l        Seconds(Event),D0
  1557. 1$        lea        PWkMWaitTime(PC),A0
  1558.         move.l        D0,(A0)
  1559.         lea        StatusBits(PC),A0
  1560.         bclr        #HMouseBlanked,(A0)
  1561.         beq.S        2$
  1562.         Prepare        Exec_Call
  1563.         CallLib        Forbid
  1564.         move.l        GFXbase(PC),A1
  1565.         move.l        gb_copinit(A1),A1
  1566.         move.w        OldSprite+0(PC),copinit_sprstrtup+2(A1)
  1567.         move.w        OldSprite+2(PC),copinit_sprstrtup+6(A1)
  1568.         Prepare        Exec_Call
  1569.         CallLib        Permit
  1570. 2$        PopS        A6
  1571.         rts
  1572.  
  1573. * Activate the window the mouse is over (if any, and if it is not
  1574. * already active).
  1575. ib_MouseY    =ib_FirstScreen+8
  1576. ib_MouseX    =ib_MouseY+2
  1577. ActivateMWindow    Push        D1-D2/A0-A2/A6
  1578.         Prepare        Exec_Call
  1579.         CallLib        Forbid
  1580.         move.l        INTUIbase(PC),A2
  1581.         move.l        ib_FirstScreen(A2),A1
  1582. ScrSLoop    move.l        A1,D0
  1583.         beq.S        DoneAMW            ; Out of screens ?
  1584.         move.w        ib_MouseX(A2),D0
  1585.         move.w        ib_MouseY(A2),D1
  1586.         move.w        sc_ViewPort+vp_Modes(A1),D2
  1587.         btst        #15,D2
  1588.         bne.S        WasHIRES
  1589.         asr.w        #1,D0
  1590. WasHIRES    btst        #2,D2
  1591.         bne.S        WasLACE
  1592.         asr.w        #1,D1
  1593. WasLACE        sub.w        sc_ViewPort+vp_DyOffset(A1),D1
  1594.         bge.S        FoundScr
  1595.         move.l        sc_NextScreen(A1),A1
  1596.         bra.S        ScrSLoop
  1597. FoundScr    lea        sc_LayerInfo(A1),A0    ; Mouse is on this screen
  1598.         move.l        LAYERbase(PC),A6
  1599.         CallLib        WhichLayer
  1600.         tst.l        D0
  1601.         beq.S        DoneAMW            ; No layer ?
  1602.         move.l        D0,A0
  1603.         move.l        lr_Window(A0),D0
  1604.         beq.S        DoneAMW            ; No window ?
  1605.         move.l        INTUIbase(PC),A6
  1606.         cmp.l        ib_ActiveWindow(A6),D0
  1607.         beq.S        DoneAMW
  1608.         move.l        D0,A0
  1609.         Call        ActivateWindow
  1610. DoneAMW        Prepare        Exec_Call
  1611.         CallLib        Permit
  1612.         Pop        D1-D2/A0-A2/A6
  1613.         rts
  1614.  
  1615. * Call:   D0:16 = ie_X/ie_Y
  1616. * Return: D0:16 = modified ie_X/ie_Y
  1617. * Calculates new mouse position using acceleration and threshold.
  1618. CalcNewPos    tst.w        D0
  1619.         bge.S        2$
  1620.         add.w        Thresh,D0
  1621.         bge.S        1$
  1622.         mulu        Accel,D0
  1623. 1$        sub.w        Thresh,D0
  1624.         rts
  1625. 2$        sub.w        Thresh,D0
  1626.         ble.S        3$
  1627.         mulu        Accel,D0
  1628. 3$        add.w        Thresh,D0
  1629.         rts
  1630.  
  1631. HandlerSize    =*-IHS
  1632.  
  1633. * The data below goes into CHIP memory
  1634. ChipData
  1635. MyCopperList    dc.w        $0180,$0000    ; Copperlist that ensures
  1636.         dc.w        $FFFF,$FFFE    ; a one-color display (black)
  1637.  
  1638. MySprite    dc.w        $FE00,$FF00    ; Invisible sprite
  1639.         dc.w        $0000,$0000
  1640.         dc.w        $0000,$0000
  1641. ChipSize    =*-ChipData
  1642.  
  1643. * »»»»»»»»»»»»»»»»»»»»»» Input-handler end «««««««««««««««««««««««««««
  1644.         END
  1645. * »»»»»»»»»»»»»»»»»»»»»»»»»» The End «««««««««««««««««««««««««««««««««
  1646.  
  1647.